<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActionMailer::TestHelper</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActionMailer::TestHelper 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../files/actionmailer/lib/action_mailer/test_helper_rb.html">actionmailer/lib/action_mailer/test_helper.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>A</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="TestHelper.html#method-i-assert_emails">assert_emails</a>,
              </li>
            
              
              <li>
                <a href="TestHelper.html#method-i-assert_no_emails">assert_no_emails</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-assert_emails">
            
              <b>assert_emails</b>(number)
            
            <a href="TestHelper.html#method-i-assert_emails" name="method-i-assert_emails" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Asserts that the number of emails sent matches the given number.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">test_emails</span>
  <span class="ruby-identifier">assert_emails</span> <span class="ruby-value">0</span>
  <span class="ruby-constant">ContactMailer</span>.<span class="ruby-identifier">welcome</span>.<span class="ruby-identifier">deliver</span>
  <span class="ruby-identifier">assert_emails</span> <span class="ruby-value">1</span>
  <span class="ruby-constant">ContactMailer</span>.<span class="ruby-identifier">welcome</span>.<span class="ruby-identifier">deliver</span>
  <span class="ruby-identifier">assert_emails</span> <span class="ruby-value">2</span>
<span class="ruby-keyword">end</span>
</pre>

<p>If a block is passed, that block should cause the specified number of
emails to be sent.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">test_emails_again</span>
  <span class="ruby-identifier">assert_emails</span> <span class="ruby-value">1</span> <span class="ruby-keyword">do</span>
    <span class="ruby-constant">ContactMailer</span>.<span class="ruby-identifier">welcome</span>.<span class="ruby-identifier">deliver</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">assert_emails</span> <span class="ruby-value">2</span> <span class="ruby-keyword">do</span>
    <span class="ruby-constant">ContactMailer</span>.<span class="ruby-identifier">welcome</span>.<span class="ruby-identifier">deliver</span>
    <span class="ruby-constant">ContactMailer</span>.<span class="ruby-identifier">welcome</span>.<span class="ruby-identifier">deliver</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-assert_emails_source')" id="l_method-i-assert_emails_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/db4af113048b5890177c1ac136f0ae7d1c066375/actionmailer/lib/action_mailer/test_helper.rb#L26" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-assert_emails_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionmailer/lib/action_mailer/test_helper.rb, line 26</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">assert_emails</span>(<span class="ruby-identifier">number</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block_given?</span>
    <span class="ruby-identifier">original_count</span> = <span class="ruby-constant">ActionMailer</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">deliveries</span>.<span class="ruby-identifier">size</span>
    <span class="ruby-keyword">yield</span>
    <span class="ruby-identifier">new_count</span> = <span class="ruby-constant">ActionMailer</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">deliveries</span>.<span class="ruby-identifier">size</span>
    <span class="ruby-identifier">assert_equal</span> <span class="ruby-identifier">original_count</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">number</span>, <span class="ruby-identifier">new_count</span>, <span class="ruby-node">&quot;#{number} emails expected, but #{new_count - original_count} were sent&quot;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">assert_equal</span> <span class="ruby-identifier">number</span>, <span class="ruby-constant">ActionMailer</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">deliveries</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-assert_no_emails">
            
              <b>assert_no_emails</b>(&amp;block)
            
            <a href="TestHelper.html#method-i-assert_no_emails" name="method-i-assert_no_emails" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Assert that no emails have been sent.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">test_emails</span>
  <span class="ruby-identifier">assert_no_emails</span>
  <span class="ruby-constant">ContactMailer</span>.<span class="ruby-identifier">welcome</span>.<span class="ruby-identifier">deliver</span>
  <span class="ruby-identifier">assert_emails</span> <span class="ruby-value">1</span>
<span class="ruby-keyword">end</span>
</pre>

<p>If a block is passed, that block should not cause any emails to be sent.</p>

<pre class="ruby"><span class="ruby-keyword">def</span> <span class="ruby-identifier">test_emails_again</span>
  <span class="ruby-identifier">assert_no_emails</span> <span class="ruby-keyword">do</span>
    <span class="ruby-comment"># No emails should be sent from this block</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Note: This assertion is simply a shortcut for:</p>

<pre>assert_emails 0</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-assert_no_emails_source')" id="l_method-i-assert_no_emails_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/db4af113048b5890177c1ac136f0ae7d1c066375/actionmailer/lib/action_mailer/test_helper.rb#L56" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-assert_no_emails_source" class="dyn-source">
                <pre><span class="ruby-comment"># File actionmailer/lib/action_mailer/test_helper.rb, line 56</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">assert_no_emails</span>(&amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">assert_emails</span> <span class="ruby-number">0</span>, &amp;<span class="ruby-identifier">block</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    